// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let {OPENID}=cloud.getWXContext()
  const _=cloud.database().command
  var date=new Date();
  return cloud.database().collection("client")
  .where({openid:OPENID})
  .update(
    { data:{
        credit:event.cre+event.quantity,
        time:event.time,
        creditRecord:_.push(
          {
            gettime:  date.getFullYear()+'年'+(date.getMonth()+1)+'月'+date.getDate()+'日',
            quantity:event.quantity,
            reason:event.reason
          })
        }
    })
}